package jgo.middleware;

import jgo.Context;
import jgo.Handler;
import jgo.core.MiddlewarePlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LoggingMiddleware extends MiddlewarePlugin {
    private static final Logger logger = LoggerFactory.getLogger(LoggingMiddleware.class);

    @Override
    public void handle(Context ctx, Handler next) {
        long startTime = System.currentTimeMillis();
        logger.info("开始处理请求: {} {}", ctx.getMethod(), ctx.getPath());

        next.handle(ctx);

        long endTime = System.currentTimeMillis();
        logger.info("请求处理完成: {} {} - 耗时: {}ms", ctx.getMethod(), ctx.getPath(), endTime - startTime);
    }
}